<?php
declare (strict_types = 1);

namespace app\controller;

use app\common\model\Feedback;
use think\facade\Cache;
use think\facade\Db;
use think\facade\View;
use think\Request;

class Ifeedback extends Common
{

    public function __construct()
    {
        parent::__construct();
    }
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {

        $cid = input("get.cid");
        if($cid){
            $where["cate_id"] = $cid;
        }
        $where["status"] =1;
        if(!isset($where)){
            $where = 1;
        }

        $list = \app\common\model\Content::with("user")
            ->where($where)
            ->order("top DESC,recommend DESC,id DESC")
            ->paginate([
                'query'=> $this->params,
            ]);
        //echo Db::name("article")->getLastSql();die;
        View::assign("list",$list);
        return  view();
    }


    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function create()
    {
        return view();
    }

    /**
     * 保存新建的资源
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function save(Request $request)
    {
        $user = $this->user;
        $d = input("post.");
        $d["userinfo"] = json_encode(session("index_user"));
        $d["uid"] = $user["id"];
        $res = Feedback::create($d);
        if($res){
            return json(["code"=>200,"msg"=>"成功"]);
        }
        return json(["code"=>400,"msg"=>"失败"]);
    }

    /**
     * 显示指定的资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function read($id)
    {
        //
    }

    /**
     * 显示编辑资源表单页.
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete($id)
    {
        //
    }

    public function cache_clear()
    {
        Cache::clear();
    }

    public function test()
    {
        return view();
    }
}
